package per.edward.wizard.ext;

import per.edward.wizard.ext.CustomDescriptor;
import per.edward.wizard.ext.WizardProxy;

/**
 * Factory class for creating WizardProxy, linear and branch ones.
 * 
 * @author xzhang
 * 
 */
public class WizardProxyFactory {

    /**
     * create a linear wizard proxy by the order of each descriptors in the
     * array.
     * <P>
     * Note: descriptors' nextPanelDescriptor/backPanelDescriptor are updated
     * after this method call.
     * </P>
     * 
     * @param descriptors
     * @return
     */
    public static WizardProxy createLinearProxy(CustomDescriptor[] descriptors) {
        for (int i = 0, n = descriptors.length; i < n - 1; i++) {
            descriptors[i].setNextPanelDescriptor(descriptors[i + 1]
                    .getPanelDescriptorIdentifier());
            descriptors[i + 1].setBackPanelDescriptor(descriptors[i]
                    .getPanelDescriptorIdentifier());
        }

        return new WizardProxy(descriptors);
    }
}
